dojo.provide("dojo.app.myvalidatorDijit.myvalidate");

dojo.declare("dojo.app.myvalidatorDijit.myvalidate", null, {
    _defaults : {bindedElement   : null,
                 triggeredEvents : ["keyup", "change", "click"],
                 processors      : [{method : 'notEmpty'}],
                 errorFunction   : "list",
                 show            : true},
    _globalOptions : {},
    _stackOfValidators : [],
    _errorShowFunctionsStack : [],
    _locale : "en",

    _self : null,

    constructor: function(optionsGlob, validators, errorShowFunc, clientLocale) {
        dojo.mixin(this._globalOptions, this._defaults, optionsGlob);
        var countVal = validators.length;
        for (var i=0; i<countVal; i++) {
            dojo.require("dojo.app.myvalidatorDijit.validators."+validators[i]);
            var newClass = new dojo.app.myvalidatorDijit.validators[validators[i]];
            this._stackOfValidators[validators[i]] = newClass;
        };

        var countErrF = errorShowFunc.length;
        for (var j=0; j<countErrF; j++) {
            dojo.require("dojo.app.myvalidatorDijit.errorviews."+errorShowFunc[j]);
            var newClass1 = new dojo.app.myvalidatorDijit.errorviews[errorShowFunc[j]];
            this._errorShowFunctionsStack[errorShowFunc[j]] = newClass1;
        };
        
        if (typeof(clientLocale)!="undefined") {
            this._locale = clientLocale.substr(0, 2);
        };

    },

    validate: function(validationElems) {
        dojo.require("dojo.app.myvalidatorDijit.validatormain");
        var countElem = validationElems.length;
        for (var i=0; i<countElem; i++) {
           var item = validationElems[i];
           //console.log(item);
           //var id = item.element.attr("id");
           var id = item.element.get("id");
           if (id != "" && id != "undefined") {
               var validationClass = new dojo.app.myvalidatorDijit.validatormain(item);
               validationClass.initOptions(this._globalOptions);
               validationClass.initValidatorsStack(this._stackOfValidators);
               validationClass.initErrorMessages(this._locale);
               validationClass.initErrorFunction(this._errorShowFunctionsStack);

               validationClass.validateElement();
           }
        };
    }

});


